package com.jack.xiaoer.web.converter;

import com.jack.xiaoer.constant.LoginTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;

/**
 * Created by Jackaroo Zhang on 2018/12/8.
 */
public class StringToLoginTypeEnum implements Converter<String, LoginTypeEnum> {

    private final Logger logger = LoggerFactory.getLogger(StringToLoginTypeEnum.class);

    @Override
    public LoginTypeEnum convert(String source) {
        try {
            return LoginTypeEnum.valueOf(source);
        } catch (IllegalArgumentException e) {
            logger.warn("LoginType convert exception, No such Element: " + source, e);
            return LoginTypeEnum.COMMON;
        }
    }
}
